package com.lanqiao.dao.impl;

import com.lanqiao.dao.BookDao;
import com.lanqiao.entity.BookInfo;
import com.lanqiao.entity.BookPicInfo;
import com.lanqiao.util.ORMUtil;

import java.util.List;

public class BookImpl implements BookDao {
    @Override
    public int insertBook(BookInfo bookInfo) {
        String sql = "insert into tb_book(book_name,book_logo_big,book_logo_small,book_price,book_price_old," +
                "book_author,book_press,book_description,store_count,type_id,`status`,is_new,is_hot)\n" +
                "values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] obj = {bookInfo.getBook_name(),bookInfo.getBook_logo_big(),bookInfo.getBook_logo_small(),
                bookInfo.getBook_price(),bookInfo.getBook_price_old(),bookInfo.getBook_author(),
                bookInfo.getBook_press(),bookInfo.getBook_description(),bookInfo.getStore_count(),
                bookInfo.getType_id(),bookInfo.getStatus(),bookInfo.getIs_new(),bookInfo.getIs_hot()
        };

        int num = new ORMUtil().executeDMLByInsert(sql, obj);



        return num;
    }

    @Override
    public int insertBookPic(BookPicInfo bookPicInfo) {
        String sql = "insert into tb_book_pic(book_id,pic_name) values (?,?)";
        int num = new ORMUtil().executeDMLByInsert(sql, bookPicInfo.getBook_id(),bookPicInfo.getPic_name());

        return num;
    }

    @Override
    public List<BookInfo> selectBook() {

        String sql="SELECT a1.*,a2.type_name FROM tb_book a1\n" +
                "INNER JOIN tb_type a2 ON a1.type_id=a2.type_id";
        List<BookInfo> bookInfos = new ORMUtil().selectList(BookInfo.class, sql);

        return bookInfos;
    }
}
